<!--This will show the Employees records-->
<?php
//written by: Marcos Resendiz
session_start();
require_once 'php_includes.php'; //query functions
require_once 'time_functions.php';//time functions

//Make sure logged in
checkLogin();	
//Make sure it is a manager logged on
checkManager();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Payroll and Timesheet Management Website</title>
    <link rel="stylesheet" type="text/css" href="styles.css"/>
  </head>
  <body>
  	<?php writeHeader(); ?>
	<p>
	<span class="pageheader">Employee timesheet reports</span><br/>
	<i><small>Click on an employee to view past submitted timesheets</small></i><br/>
	</p>
	
		<?php
		//Establishes connection to the database
		sqlConnect();
		//Will hold the users ID.
		$managerID=$_SESSION['tmsUserID'];
		//Will retrieve the people with the same manager ID from the Employee table
		$SQLstring="SELECT * FROM Employee WHERE ManagerID= '$managerID'";
		//will perform the query and hold the results
		$QueryResult=sqlQuery($SQLstring);
		//this will display the table with the employees that have the same manager ID
			echo"<table class='full'>";
			echo"<tr><th></th><th>ID</th><th>Employee Name</th><th>Title</th><th>Department</th><th>Records</th></tr>";
			//Will hold the amount of row numbers.
			$Row = mysql_fetch_row($QueryResult);
			do //While there is still rows
			{
				$fName=$Row[3];	//Will hold the first name
				$lName=$Row[4];	//Will hold the last name
				$space=' ';		//Blank space
				$empID=$Row[0];	// Will hold the ID number
				$recNum = ceil(mysql_num_rows(sqlQuery("select * FROM PayPeriod WHERE EmployeeID= '$empID'")));//will hold the amout of records found for the employee
			
				$user=$Row[0];//will hold the Employee ID to be sent post.
				//Table is printed with the results
				echo"<tr><td class='view'><form action='previoustime.php' method='post'><div>";
				echo"<input type='hidden' name='usertime' value='$user' />";
				echo"<input type='submit' value='View' class='button' /></div></form></td>";
				echo"<td name='userID' class='id'>{$Row[0]}</td><td name='userName' class='record'>{$fName}{$space}{$lName}  </td>";
				echo"<td name='userTitle' class='record'>{$Row[5]}</td><td name='userDept' class='record'>{$Row[7]}</td>";
				echo"<td name='userRec' class='record'>";
				 if($recNum==0) //if there are no records found it will display "NO RECORDS".
				 echo('NO RECORDS'); 
				 else	//else if will display the number of records found
				 echo($recNum); 
				echo"</td></tr>";
				$Row=mysql_fetch_row($QueryResult);
			}while($Row);
			//closes the DB
		sqlExit();
			?>
	  </body>
</html>